package com.hskn.hss.module.instorageCfg.controller;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hskn.hss.core.annotation.SysLog;
import com.hskn.hss.core.enums.BusinessType;
import com.hskn.hss.entity.AjaxResult;
import com.hskn.hss.exception.HssException;
import com.hskn.hss.module.dlbjviolation.entity.DlbjViolation;
import com.hskn.hss.module.inspectionCfg.mapper.TlInspectionCfgMapper;
import com.hskn.hss.module.instorageCfg.entity.TlInStorageCfg;
import com.hskn.hss.module.instorageCfg.mapper.TlInStorageCfgMapper;
import com.hskn.hss.module.instorageCfg.service.ITlInStorageCfgService;
import com.hskn.hss.utils.Tools;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author hskn
 * @since 2021-05-08
 */
@Slf4j
@RestController
@RequestMapping("/hss/tlinstoragecfg")
public class TlInStorageCfgController {
    @Autowired
    private ITlInStorageCfgService tlInStorageCfgService;

    /***
     * 新增
     * @param request
     * @return
     */
    //@SysLog(businessType = BusinessType.INSERT, bean = TlInStorageCfg.class, beanMapper = TlInStorageCfgMapper.class, names = "serialnumber")
    @RequestMapping(value = "insert", method = RequestMethod.POST)
    public AjaxResult<Object> insert(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            return tlInStorageCfgService.insert(params);
        } catch (HssException e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败，请稍后再试");
        }
    }

    /**
     * 修改
     *
     * @param request
     * @return
     */
    //@SysLog(businessType = BusinessType.UPDATE, idKey = "id", beanMapper = TlInStorageCfgMapper.class, names = "serialnumber")
    @RequestMapping(value = "update", method = RequestMethod.POST)
    public AjaxResult<Object> update(HttpServletRequest request) {
        try {
            JSONObject params = JSON.parseObject(Tools.getBody(request));
            return tlInStorageCfgService.update(params);
        } catch (HssException e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败，请稍后再试");
        }
    }

    /**
     * 根据Id获取
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "getbyid", method = RequestMethod.POST)
    public AjaxResult<Object> getbyid(HttpServletRequest request) {
        JSONObject params = JSON.parseObject(Tools.getBody(request));
        TlInStorageCfg tlInStorageCfg = null;
        try {
            tlInStorageCfg = tlInStorageCfgService.getDetailById(params);
            return AjaxResult.success(tlInStorageCfg);
        } catch (HssException e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }


    }

    /**
     * 获取列表
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "getlist", method = RequestMethod.POST)
    public AjaxResult<Object> getlist(HttpServletRequest request) {
        JSONObject params = JSON.parseObject(Tools.getBody(request));
        try {
            JSONObject json = tlInStorageCfgService.getList(params);
            return AjaxResult.success(json);
        } catch (HssException e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("获取信息失败，请稍后再试");
        }

    }

}

